from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

# 你的 chromedriver.exe 路径
driver_path = "D:/桌面/Application/chromedriver.exe"
service = Service(driver_path)

# 初始化 WebDriver
driver = webdriver.Chrome(service=service)

# 访问 Bing
url = "https://cn.bing.com/"
driver.get(url)

# 查找搜索框
box = driver.find_element(By.NAME, "q")  # 用 By.NAME 替代 By.XPATH，更稳定
box.clear()  # 先清空再输入
box.send_keys("python 自动化测试")

# 提交搜索
box.submit()

# 等待 5 秒，方便观察执行结果
import time
time.sleep(10)

# 关闭浏览器，释放资源
driver.quit()